package ift604.projet.utils;

import com.google.android.maps.GeoPoint;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;

public class GeoPosition {

    public static Location currentGeoPosition(Activity activity) {
        Location location = null;

        try {
            LocationManager lm = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
            location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        }
        catch (Exception e) {
            Log.e(activity.getClass().getName(), e.toString());
        }

        return location;
    }
    
	/**
	 * Creation d'une classe GeoPoint a partir d'une Location
	 */
	public static GeoPoint locationToGeoPoint(Location location) {
		return locationToGeoPoint(location.getLatitude(), location.getLongitude());
	}
	
	/**
	 * Creation d'une classe GeoPoint a partir d'une latitude et longitude
	 */
	public static GeoPoint locationToGeoPoint(double latitude, double longitude) {
		return new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
	}
}
